import java.util.Stack;

class MinStack {

    Stack<Integer> stack;
    Stack<Integer> minstack;

    public MinStack() {
        stack = new Stack<>();
        minstack = new Stack<>();
    }
    
    public void push(int val) {
        stack.push(val);
        if (minstack.isEmpty()){
            minstack.push(val);
        }else {
            int maxMin = minstack.peek();
            if (val <= maxMin){
                minstack.push(val);
            }
        }

    }
    
    public void pop() {
        int val = stack.pop();
        if (val == minstack.peek()){
            minstack.pop();
        }

    }
    
    public int top() {
        return stack.peek();

    }
    
    public int getMin() {
        return minstack.peek();
    }
}